package com.example.neusoft.yuejian_12.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.neusoft.yuejian_12.Adapter.ContestAdapter;
import com.example.neusoft.yuejian_12.JavaBean.Contest;
import com.example.neusoft.yuejian_12.Listener.ContestListener;
import com.example.neusoft.yuejian_12.Model.ContestModel;
import com.example.neusoft.yuejian_12.R;

import java.util.List;

public class ContestFragment extends Fragment implements ContestListener {

    private RecyclerView recyclerView;
    List<Contest> list;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState)
    {
        View view=inflater.inflate(R.layout.fragment_contest, container, false);
        initRecyclerView(view);
        ContestModel model=new ContestModel();
        model.getList("id","name",this);
        return  view;
    }

    public  void initRecyclerView(View view){

        recyclerView=(RecyclerView) view.findViewById(R.id.rv_contest);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public void onResponse(List<Contest> listBean) {
        list=listBean;
        recyclerView.setAdapter(new ContestAdapter(getActivity(),list));
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(getActivity(), "hhh"+msg, Toast.LENGTH_SHORT).show();
    }

}
